{extend name="base"}
{block name="title"}代理返点管理{/block}
{block name="head"}
<style>
  .border-table tbody th{text-align:center; color:#333; font-weight:400; padding-left:5px;}
  .border-table{font-size:12px; color:#666;}
  .border-table th, .border-table td{text-align:center; padding:0 4px;}
  .icon-open, .icon-close{cursor:pointer;}
</style>
<script src="__STATIC__/common/avalon.mobile-2.2.9.min.js"></script>
<script>
$(function () {
  $('.icon-open, .icon-close').live('click', function (e) {
    var _this = $(this);
    var open = _this.hasClass('icon-open');
    var tr = _this.closest('tr');
    var cc = $('td:eq(2) i.icon', tr).length;
    var ar = [];
    $.each(tr.nextAll('tr'), function (k, v) {
      var ax = $(v).find('td:eq(2) i.icon').length;
      if (ax > cc) {
        ar.push(v);
      } else {
        return false;
      }
    });
    console.log(ar);
    if (open) {
      console.log("折叠");
      _this.removeClass('icon-open').addClass('icon-close');
      $(ar).hide();
    } else {
      console.log("展开");
      _this.removeClass('icon-close').addClass('icon-open');
      $(ar).find('td:eq(2) i.icon-close').removeClass('icon-close').addClass('icon-open');
      $(ar).show();
    }
  });
  
  $('input.a').click(function(){
    console.log("结算");
    var uid = $(this).parents('tr').data('uid')
    dialog({
      title: '提示',
      content: '确认结算选中用户[' + uid + ']?',
      okValue: '确定',
      ok: function () {
        $.post("{:url('user.agent/jiesuan')}?UserID=" + uid, function (resp, text, xhr) {
          console.log(resp);
          if (resp.errno == 0) {
            location.reload();
          } else {
            alert(resp.error);
          }
        });
        return false;
      },
      cancelValue: '取消',
      cancel: function () {}
    }).showModal();
  });
  $('input.b').click(function(){
    var uid = $(this).parents('tr').data('uid')
    var channel = $(this).parents('tr').data('chan')
    var name = $(this).parents('tr').data('name')
    dialog({
      width:240,
      height:80,
      title: '提示',
      content: '<span style="font-size: 14px;color: red;">确认删除选中代理[' + uid + ']'+name+'?</span>>',
      okValue: '确定',
      ok: function () {
        $.post("{:url('user.agent/delagent')}?UserID=" + uid+"&channel="+channel, function (resp, text, xhr) {
          if (resp.errno == 0) {
            alert(resp.error)
            location.reload();
          } else {
            alert(resp.error);
          }
        });
        return false;
      },
      cancelValue: '取消',
      cancel: function () {}
    }).showModal();
  });
});
</script>
{/block}
{block name="body"}
<body class="mainbody ms-controller" ms-controller="AgentALL">
<form>
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>代理返点管理</span>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
        <div class="menu-list">
          <div class="rule-single-select">
            <select name="channel" style="display:none">
              {volist name="CHANNELS" id="val"}
              <option value="{$key}"{eq name="channel" value="$key"} selected{/eq}>[{$key}]{$val.Name}</option>
              {/volist}
            </select>
          </div>
          <div class="rule-single-select">
            <select name="DisableLogin" style="display:none">
              <option value="2"{eq name="DisableLogin" value="2"} selected{/eq}>可否登陆</option>
              <option value="0"{eq name="DisableLogin" value="0"} selected{/eq}>允许登陆</option>
              <option value="1"{eq name="DisableLogin" value="1"} selected{/eq}>禁止登陆</option>
            </select>
          </div>
        </div>
      </div>
      <div class="r-list">
        <label style="color:#f00;">总金额:{:number_format($Total['Charge'], 2, '.', '')}</label>
        <label>总佣金:{:number_format($Total['Rebate'], 2, '.', '')}</label>
        <label>总利润:{:number_format($Total['Charge'] - $Total['Rebate'], 2, '.', '')}</label>
        <label>佣金池:<a target="_blank" href="#AccountsSysConfig.aspx">{:number_format($CashPool, 2, '.', '')}</a></label>
        <label>业绩:{:number_format($dddd, 2, '.', '')}</label>
        <label>佣金:{:number_format($eeee, 2, '.', '')}</label>
        <label>利润:{:number_format($dddd - $eeee, 2, '.', '')}</label>
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->

<!--列表-->
<div class="table-container">
<table class="ltable border-table" data-auto="">
  <tr>
    <th>渠道</th>
    <th>代理标识</th>
    <th>代理姓名</th>
    <th>代理级别</th>
    <th>邀请码</th>
    <th>绑定人数</th>
    <th>总业绩</th>
    <th>一级返点</th>
    <th>二级返点</th>
    <th>三级返点</th>
    <th>合计佣金</th>
    <th>上次结算金额</th>
    <th>上次结算时间</th>
    <th>可否登陆</th>
    <th>其它操作</th>
    <th>清除代理</th>
  </tr>

  <!-- icon iconfont icon-open 结点展开-->
  <!-- icon iconfont icon-close 折叠 -->
  <!-- icon iconfont icon-csac 子节点展开 -->

  
{php}function render_tr($elm, $deep=0){{/php}
  {notempty name="elm"}
    {volist name="elm" id="a"}
      <tr data-uid="{$a.UserID}" data-chan="{$a.Channel}" data-name="{$a.Compellation|htmlentities}">
        <td title="{$a.Channel}">{$a.Channel}</td>
        <td>{$a.UserID}</td>
        <td style="text-align:left">
          {for start="-1" end="$deep"}
            {if condition="($i EQ $deep-1) AND !empty($a._child)"}
              <i class="icon iconfont icon-open" title="{$i}"></i>
            {else/}
              <i class="icon iconfont icon-csac" title="{$i}"></i>
            {/if}
          {/for}
          <a target="_blank" href="{:url('user.detail/index')}?UserID={$a.UserID}">[{$deep}]-{$a.Compellation|htmlentities}</a>
        </td>
        <td>[{$a.AgentLevel}]{$a.AgentLevelName}</td>
        <td><a target="_blank" class="input" href="{:url('user.agent.qrcode/build')}?GameID={$a.GameID}">{$a.GameID}</a></td>
        <td><a target="_blank" href="{:url('user.agent.bind/index')}?search2={$a.GameID}">{$a.BindCount}</a></td>
        <td><a target="_blank" href="{:url('user.pay/index')}?search={$a.GameID}&time1={$a.RebateTime}">{$a.Rebate*1}</a></td>
        <td>{$a.RebateMax0*1}</td>
        <td>{$a.RebateMax1*1}</td>
        <td>{$a.RebateMax2*1}</td>
        <td><a target="_blank" href="{:url('user.pay/rebate')}?search={$a.UserID}&time1={$a.RebateTime}">{$a.myRebate2*1}</a></td>
        <td>{$a.RebateRMB*1}</td>
        <td>{$a.RebateTime}</td>
        <td style="color:{$a.DisableLogin?'red':'green'}">{$a.DisableLogin?'禁止':'允许'}</td>
        <td>
          <input type="button" class="a" value="结算">
        </td>
        <td>
          <input type="button" class="b" value="删除">
        </td>
      </tr>
      {notempty name="a._child"}
        {php}render_tr($a['_child'], $deep+1);{/php}
      {/notempty}
    {/volist}
  {/notempty}
{php}}{/php}
  
{empty name="tree"}
  <tr><td colspan="15">Oh~暂无数据!</td></tr>
{else/}
  {php}render_tr($tree, 0);{/php}
{/empty}

</table>
</div>
<!--/列表-->

<!--内容底部-->
<div class="page-footer"><div class="btn-wrap">{$page->render()}</div></div>
<!--/内容底部-->

</form>
<script>
avalon.ready(function () {
  var tree = {$tree|default=[]|json_encode=JSON_UNESCAPED_UNICODE};
  var CHANNELS = {$CHANNELS|default=[]|json_encode=JSON_UNESCAPED_UNICODE};
  var vm = avalon.define({
    $id: "AgentALL",
    CHANNELS: CHANNELS,
    tree: tree
  });
  avalon.scan(document.body);
});
</script>
</body>
{/block}